//
//  TabBarItem.swift
//  CustomTabbar
//
//  Created by chenxihang on 2024/8/18.
//

import SwiftUI

struct TabBarItem: View {
    
    @StateObject var viewRouter: ViewRouter
    let page: Page
    
    let width: CGFloat
    let height: CGFloat
    let icon: String
    let text: String
    
    var body: some View {
        VStack(content: {
            Image(systemName: icon)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: width, height: height)
                .padding(.top, 2)
            
            Text(text)
                .font(.footnote)
                .font(.system(size: 16))
            
        })
        .padding(.horizontal, -2)
        .onTapGesture(perform: {
            viewRouter.currentPage = page
        })
        .foregroundColor(viewRouter.currentPage == page ? .blue : .gray)
    }
}

#Preview {
    TabBarItem(viewRouter: ViewRouter(), page: .home, width: 40, height: 40, icon: "chart.pie.fill", text: "首页")
}
